package day20;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class MainTest {
    public static void main(String[] args) {
        Set set = new HashSet();
        String s1 = new String("java");
        String s2 = s1;
        set.add(s1);
        System.out.println("集合大小："+ set.size());
        set.add(s2);
        System.out.println("集合大小："+ set.size());
        String s3= new String("JAVA");
        set.add(s3);
        System.out.println("集合大小："+ set.size());
        //如何取值遍历
        Iterator iterable =  set.iterator();
        while (iterable.hasNext()){
            System.out.println(iterable.next());
        }
        //简写方式  增加for循环
        for (Object st:set){
            System.out.println(st);
        }
        //现有数组 2,4，5,2,6,6,9
        //  去重复  2,4,5,6,9
        int[] nums = {2,4,5,2,6,6,9};
        Set set1 = new HashSet();
        for (int num:nums){
            set1.add(nums);
        }
    }
}
